﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleCalculator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("输入两个数字，用空格分隔（如输入多个，只会读取前两个）：");
            string[] a= Console.ReadLine().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            double a1, a2;
            try
            {
                a1 = double.Parse(a[0]);
                a2 = double.Parse(a[1]);
                Console.Write("输入四则运算符：");
                char b = Console.ReadLine().Trim()[0];
                double res;
                switch (b)
                {
                    case '+':
                        res = a1 + a2;break;
                    case '-':
                        res = a1 - a2;break;
                    case '*':
                        res = a1 * a2;break;
                    case '/':
                        res = a1 / a2;break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
                Console.WriteLine($"结果为{res}");
            }
            catch(IndexOutOfRangeException)
            {
                Console.WriteLine("输入数据不够");
            }
            catch(FormatException)
            {
                Console.WriteLine("输入的不是数字");
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine("输入的不是四则运算符");
            }
            finally
            {
                Console.ReadKey();
            }
        }
    }
}
